<?php

App::uses('AppController', 'Controller');

/**
 * Productcategories Controller
 *
 * @property Productcategory $Productcategory
 * @property PaginatorComponent $Paginator
 * @property SessionComponent $Session
 */
class AdminProductcategoriesController extends AppController
{

    public $name = 'AdminProductcategories';
    public $components = array(
        'Acl',
        'Auth' => array(
            'authorize' => array(
                'Actions' => array('actionPath' => 'controllers')
            ),
            'authenticate' => array(
                'Form' => array(
                    'fields' => array('username' => 'email')
                )
            )
        ),
    );
    public $uses = array('Productcategory');

    public function beforeFilter()
    {
        parent::authorizeAdmin();
    }

    /**
     * admin_index method
     *
     * @return void
     */
    public function admin_index()
    {

        $this->Productcategory->recursive = 0;
        $this->set('productcategories', $this->Paginator->paginate());

        $this->render('/Admin/Productcategories/index');
    }

    /**
     * admin_add method
     *
     * @return void
     */
    public function admin_add()
    {
        if ($this->request->is('post')) {
            $this->Productcategory->create();
            if ($this->Productcategory->save($this->request->data)) {
                $this->Session->setFlash(__('The productcategory has been saved.'));
                return $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The productcategory could not be saved. Please, try again.'));
            }
        }

        $this->render('/Admin/Productcategories/add');
    }

    /**
     * admin_edit method
     *
     * @throws NotFoundException
     * @param string $id
     * @return void
     */
    public function admin_edit($id = null)
    {
        if (!$this->Productcategory->exists($id)) {
            throw new NotFoundException(__('Invalid productcategory'));
        }
        if ($this->request->is(array('post', 'put'))) {
            if ($this->Productcategory->save($this->request->data)) {
                $this->Session->setFlash(__('The productcategory has been saved.'));
                return $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The productcategory could not be saved. Please, try again.'));
            }
        } else {
            $options = array('conditions' => array('Productcategory.' . $this->Productcategory->primaryKey => $id));
            $this->request->data = $this->Productcategory->find('first', $options);
        }

        $this->render('/Admin/Productcategories/edit');
    }

    /**
     * admin_delete method
     *
     * @throws NotFoundException
     * @param string $id
     * @return void
     */
    public function admin_delete($id = null)
    {
        $this->Productcategory->id = $id;
        if (!$this->Productcategory->exists()) {
            throw new NotFoundException(__('Invalid productcategory'));
        }
        $this->request->allowMethod('post', 'delete');
        if ($this->Productcategory->delete()) {
            $this->Session->setFlash(__('The productcategory has been deleted.'));
        } else {
            $this->Session->setFlash(__('The productcategory could not be deleted. Please, try again.'));
        }
        return $this->redirect(array('action' => 'index'));
    }

}
